package com.gitee.cui.springcloud.controller;

import java.util.HashMap;
import java.util.Map;

import com.gitee.cui.springcloud.entities.CommonResult;
import com.gitee.cui.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022-03-20 12:14
 **/
@RestController
@Slf4j
public class PaymentController {

	@Value("${server.port}")
	private String serverPort;

	private static Map<Long, String> map = new HashMap<>();

	static {
		map.put(1L, "hiuasdjbndfklgjoiasdf001");
		map.put(2L, "hiuasdjbndfklgjoiasdf002");
		map.put(3L, "hiuasdjbndfklgjoiasdf003");
	}

	@GetMapping("/payment/{id}")
	public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
		String result = map.get(id);
		CommonResult<Payment> cr;
		if (result != null) {
			cr = new CommonResult<>(200, "query from mysql, serverPort: " + serverPort, new Payment(id, result));
		} else {
			cr = new CommonResult<>(444, "query from mysql, but query nothing, serverPort: " + serverPort);
		}
		return cr;
	}
}
